function dateConvert(date) {//传入一个日期类型 剪切
  if (date) {
    return date.replace("T", " ")
  }
  return "null"
}
function req({ url,data, success , fail}) {
  var util = require('promisify'); 
  var request = util(wx.request);
  request({ url,data}).then(res => {
    typeof success == "function" && success(res)
  }).catch(err => { typeof fail == "function" && fail(err) })

  //云函数的请求

 /* wx.cloud.callFunction({
    name: "gethttp",
    data: {
      url: url,
      dat: data
    },
    success: (res) => {
      var result = {
        statusCode: 200, data: JSON.parse(res.result) //回来的云函数转为JSON  否则就是默认的字符串
      }
      typeof success == "function" && success(result)
    },
    fail: (err) => {
      var result = {
        statusCode: 500, data: ""
      }
      typeof success == "function" && success(result)
    }
  })*/
}

function getPoleInfo({ success }) {
  var util = require('promisify');
  var request = util(wx.request);
  request({
    url: getApp().appData.site + 'accp/psPoleInfo/getPoleInfo',
    data: {
      lineId: 0,
      isStart: 2
    }
  }).then(res => {
    var myFor = [];
    for (var i in res.data) {
      myFor.push({
        name: res.data[i].poleCode,
        value: res.data[i].id
      })
    }
    typeof success == "function" && success(myFor)
  }).catch(err => console.log(err));
}

module.exports = {
  dateConvert: dateConvert,
  req: req,
  getPoleInfo: getPoleInfo
}